package by.bsu.scs.presentation.form;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.upload.FormFile;
import org.apache.struts.util.LabelValueBean;

import by.bsu.scs.model.DisciplineInstructor;
import by.bsu.scs.model.Mark;
import by.bsu.scs.model.TaskAttachment;
import by.bsu.scs.util.form.StudentTask;

public class TaskForm extends ActionForm{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private ArrayList<DisciplineInstructor> disciplineInstructorList;
	private ArrayList<LabelValueBean> disciplineList;
	private ArrayList<Mark> markList;
	private ArrayList<StudentTask> studentTaskList;
	private StudentTask studentTask;
	private int disciplineId;
	private int countUncheckedTasks;

	private FormFile  solutionFile; 
	
	// ******** For teacher ********
	private ArrayList<TaskAttachment> uncheckedTaskList;
	
	
	public TaskForm() {
		super();
		// TODO Auto-generated constructor stub
	}
		
		
	public FormFile getSolutionFile() {
		return solutionFile;
	}

	public void setSolutionFile(FormFile solutionFile) {
		this.solutionFile = solutionFile;
	}



	public ArrayList<LabelValueBean> getDisciplineList() {
		return disciplineList;
	}


	public void setDisciplineList(ArrayList<LabelValueBean> disciplineList) {
		this.disciplineList = disciplineList;
	}


	public int getDisciplineId() {
		return disciplineId;
	}


	public void setDisciplineId(int disciplineId) {
		this.disciplineId = disciplineId;
	}


	public ArrayList<DisciplineInstructor> getDisciplineInstructorList() {
		return disciplineInstructorList;
	}

	public void setDisciplineInstructorList(ArrayList<DisciplineInstructor> disciplineInstructorList) {
		this.disciplineInstructorList = disciplineInstructorList;
	}

	public ArrayList<StudentTask> getStudentTaskList() {
		return studentTaskList;
	}

	public void setStudentTaskList(ArrayList<StudentTask> studentTaskList) {
		this.studentTaskList = studentTaskList;
	}

	public ArrayList<Mark> getMarkList() {
		return markList;
	}
	public void setMarkList(ArrayList<Mark> markList) {
		this.markList = markList;
	}


	public StudentTask getStudentTask() {
		return studentTask;
	}


	public void setStudentTask(StudentTask studentTask) {
		this.studentTask = studentTask;
	}
	
	public ArrayList<TaskAttachment> getUncheckedTaskList() {
		return uncheckedTaskList;
	}

	public void setUncheckedTaskList(ArrayList<TaskAttachment> uncheckedTaskList) {
		this.uncheckedTaskList = uncheckedTaskList;
	}
	
	public int getCountUncheckedTasks() {
		return countUncheckedTasks;
	}

	public void setCountUncheckedTasks(int countUncheckedTasks) {
		this.countUncheckedTasks = countUncheckedTasks;
	}
	
	/**
	 * @param mapping
	 * @param request
	 * 
	 * @return errors
	 */
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();

		if (this.solutionFile != null) {
			/*
			 * If the file is exist.
			 */
			if(this.solutionFile.getFileName().length() < 1){
				errors.add("solutionFileNotExist", new ActionMessage(
				"error.fileSolution.exist"));
			}
			/*
			 * If the file size is greater than 20kb.
			 */
			if (this.solutionFile.getFileSize() > 1024 * 20) {
				errors.add("solutionFileSiseGreat", new ActionMessage(
						"error.fileAttach.size"));
			}
			/*
			 * If the number of upload is equal maxUpload.
			 */
			if(this.studentTask.getNumberUpload() == this.studentTask.getTask().getMaxUpload()){
				errors.add("solutionFileMaxUpload", new ActionMessage(
				"error.fileAttach.maxUpload"));
			}
		}
		return errors;
	}
}
